from rest_framework import serializers
from .models import *


# 优惠券的序列化器
class CouponSer(serializers.ModelSerializer):
    good_name = serializers.SerializerMethodField(read_only=True)
    def get_good_name(self, obj):
        return obj.good.name


    class Meta:
        model = Coupon
        fields = "__all__"
        read_only_fields = ["id",]


# 优惠券类型的序列化器
class CouponTypeSer(serializers.ModelSerializer):

    class Meta:
        model = CouponType
        fields = "__all__"
